export function setSession(key: string, value: any) {
  if (key && typeof key === "string") {
    if (typeof value === "object") {
      const val = JSON.stringify(value);
      window.sessionStorage.setItem(key, val);
    } else if (typeof value === "string") {
      window.sessionStorage.setItem(key, value);
    } else {
      window.sessionStorage.setItem(key, value);
    }
  }
}

export function getSession(key: string) {
  const str = window.sessionStorage.getItem(key);
  if (str && typeof str === "string") {
    if (str.indexOf("}") > -1 || str.indexOf("]") > -1) {
      return JSON.parse(str);
    }
    return str;
  }
  return str;
}

export function removeSession(key: string) {
  if (key) {
    window.sessionStorage.removeItem(key);
  } else {
    window.sessionStorage.clear();
  }
}
